package com.kmproject.haifu.mvp.ui.adapter;

import android.content.pm.ActivityInfo;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.integration.AppManager;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.AppConstant;
import com.kmproject.haifu.app.utils.Glide4Engine;
import com.kmproject.haifu.mvp.model.entity.beans.HouseRentListShowInfoBean;
import com.kmproject.haifu.mvp.model.entity.beans.SecondHandInfoBean;
import com.kmproject.haifu.mvp.presenter.SecondHandPublicshPresenter;
import com.kmproject.haifu.mvp.ui.widget.Subject;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.internal.entity.CaptureStrategy;

import java.util.List;

public class SecondHandPublishAddImgAdapter extends BaseQuickAdapter<SecondHandInfoBean.ImagesBean,BaseViewHolder> {
    private final int FIRST_TOP_VIEW=1000;
    ImageLoader glideImage;
    private int maxNumImg=9;
    private boolean isShowDelImg=true;
    SecondHandPublicshPresenter msecondHandPublicshPresenter;
    public SecondHandPublishAddImgAdapter(@Nullable List<SecondHandInfoBean.ImagesBean> data, SecondHandPublicshPresenter secondHandPublicshPresenter) {
        super(R.layout.secondhandpublish_add_img_item,data);
           msecondHandPublicshPresenter=secondHandPublicshPresenter;
    }
    public void setShowDelImg(boolean showDelImg) {
        isShowDelImg = showDelImg;
    }

    public void setMaxNumImg(int maxNumImg) {
        this.maxNumImg = maxNumImg;
    }

    @Override
    protected void convert(BaseViewHolder helper, SecondHandInfoBean.ImagesBean item) {
        if (glideImage == null) {
            glideImage = ArmsUtils.obtainAppComponentFromContext(mContext).imageLoader();
        }
        if (!isShowDelImg){
            helper.<ImageView>getView(R.id.add_img_item_del).setVisibility(View.GONE);
        }
        helper.addOnClickListener(R.id.add_img_item_del);


        if (helper.getPosition()==getItemCount()-1)
        {
            helper.<ImageView>getView(R.id.add_img_item_img).setImageResource(R.drawable.secondhand_add_img_bg);
            helper.<ImageView>getView(R.id.add_img_item_del).setVisibility(View.GONE);

            helper.<ImageView>getView(R.id.add_img_item_img).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (getItemCount()-1==maxNumImg)
                    {
                        ArmsUtils.makeText(mContext,"最多只能选取"+maxNumImg+"张图片");
                        return;
                    }
                    msecondHandPublicshPresenter.requestPrisession();
                }
            });
        }else {
            if (helper.getPosition()==0)
            {
                helper.<TextView>getView(R.id.add_img_item_ts).setVisibility(View.VISIBLE);
            }else {
                helper.<TextView>getView(R.id.add_img_item_ts).setVisibility(View.GONE);
            }
            helper.<ImageView>getView(R.id.add_img_item_del).setVisibility(View.VISIBLE);
               glideImage.loadImage(mContext, ImageConfigImpl.builder().url(item.getImageUrl())
                       .imageView(helper.<ImageView>getView(R.id.add_img_item_img))
                       .build());


            helper.addOnClickListener(R.id.add_img_item_img);
        }
    }

}
